﻿using Sprout.Repository;
using Sprout.Schedule.Dtos;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Sprout.Schedule.Daos
{
    [Repository(DataSource = "Schedule")]
    public interface ITaskDao : IRepository
    {
        #region 异步
        /// <summary>
        /// 新增任务
        /// </summary>
        /// <param name="taskInfo"></param>
        /// <returns>主键ID</returns>
        [Execute(ReturnId = true, StatementId = "Insert")]
        Task<long> InsertAsync(TaskInfo taskInfo);

        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="taskInfo"></param>
        /// <returns></returns>
        [Execute(StatementId = "Delete")]
        Task DeleteAsync(TaskInfo taskInfo);

        /// <summary>
        /// 查询详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Select(StatementId = "GetDetail")]
        Task<TaskInfo> GetDetailAsync(TaskQuery query);

        /// <summary>
        /// 查询任务列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Select(StatementId = "Gets")]
        Task<IList<TaskInfo>> GetsAsync(TaskQuery query);

        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="taskInfo"></param>
        /// <returns>受影响的行数</returns>
        [Execute(StatementId = "Update")]
        Task<int> UpdateAsync(TaskInfo taskInfo);

        /// <summary>
        /// 修改任务状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>受影响的行数</returns>
        [Execute(StatementId = "UpdateStatus")]
        Task<int> UpdateStatusAsync(TaskInfo dto);

        /// <summary>
        /// 任务开始运行
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>受影响的行数</returns>
        [Execute(StatementId = "Run")]
        Task<int> RunAsync(TaskInfo dto);

        /// <summary>
        /// 任务运行结束
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>受影响的行数</returns>
        [Execute(StatementId = "RunEnd")]
        Task<int> RunEndAsync(TaskInfo dto);

        /// <summary>
        /// 修改最后执行的值
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [Execute(StatementId = "UpdateRunValue")]
        Task<int> UpdateRunValueAsync(TaskInfo dto);

        #endregion

        #region 同步
        /// <summary>
        /// 任务开始运行
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>受影响的行数</returns>
        [Execute]
        int Run(TaskInfo dto);

        /// <summary>
        /// 任务运行结束
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>受影响的行数</returns>
        [Execute]
        int RunEnd(TaskInfo dto);

        /// <summary>
        /// 修改最后执行的值
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [Execute]
        int UpdateRunValue(TaskInfo dto);
        /// <summary>
        /// 查询详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Select]
        TaskInfo GetDetail(TaskQuery query);

        #endregion
    }
}
